package com.ruoyi.web.controller.drug;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.drug.domain.DrugsOrder;
import com.ruoyi.drug.service.IDrugsOrderService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单
 * Controller
 *
 * @author ruoyi
 * @date 2022-11-13
 */
@RestController
@RequestMapping("/drug/order")
public class DrugsOrderController extends BaseController {
    @Autowired
    private IDrugsOrderService drugsOrderService;

    /**
     * 查询订单
     * 列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(DrugsOrder drugsOrder) {
        startPage();
        List<DrugsOrder> list = drugsOrderService.selectDrugsOrderList(drugsOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单
     * 列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DrugsOrder drugsOrder) {
        List<DrugsOrder> list = drugsOrderService.selectDrugsOrderList(drugsOrder);
        ExcelUtil<DrugsOrder> util = new ExcelUtil<DrugsOrder>(DrugsOrder.class);
        util.exportExcel(response, list, "订单数据");
    }

    /**
     * 获取订单
     * 详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId) {
        return success(drugsOrderService.selectDrugsOrderByOrderId(orderId));
    }

    /**
     * 新增订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public int add(@RequestBody DrugsOrder drugsOrder) {
        return drugsOrderService.insertDrugsOrder(drugsOrder);
    }

    /**
     * 修改订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DrugsOrder drugsOrder) {
        return toAjax(drugsOrderService.updateDrugsOrder(drugsOrder));
    }

    /**
     * 删除订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds) {
        return toAjax(drugsOrderService.deleteDrugsOrderByOrderIds(orderIds));
    }
}
